import router from "@/router";
import axios from "axios";

let http = axios.create({
  baseURL: 'http://api.quanjiu.net/estate/',
  timeout: 10000,
  headers: { 'Content-Type': 'application/json' },
})
http.interceptors.request.use(
  config => {
    config.headers['Authorization'] = sessionStorage.getItem('token')
    return config;
  },
  error => {
    // 请求错误处理
    return Promise.reject(error);
  }
);

// 响应拦截器
http.interceptors.response.use(
  response => {
    if (response.data.errCode == "10000") {
      return response.data;
    }
    if (response.data.errCode == "10200") {
      router.push("/")
    }
    // 对响应数据做处理，例如只返回data部分

  },
  error => {
    // 响应错误处理
    return Promise.reject(error);
  }
);
export default http